package de.mssp.sensorkit.wlan;

import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.widget.Toast;

public class WiFiScanReceiver extends BroadcastReceiver 
{
	WLANActivity wifiAct;

	public WiFiScanReceiver(WLANActivity wifi) 
	{
		super();
		this.wifiAct = wifi;
	}

	@Override
	public void onReceive(Context c, Intent intent) 
	{	
		//Gather result from wifiManager
		List<ScanResult> results = wifiAct.wifiMan.getScanResults();

		//Show Toast Message
		String message = String.format("%s networks found.", results.size());
		Toast.makeText(wifiAct, message, Toast.LENGTH_LONG).show();
		
		//Add each found device to the Wifi-List
		for(ScanResult sr: results)
		{
			wifiAct.addNetworkToMap(sr);
		}
	}
}
